package com.iob.coin.DAO;

import com.iob.coin.po.Triple;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import javax.persistence.Entity;
import javax.transaction.Transactional;
import java.util.List;

/**
 * @Author: MengYuxin
 * @Date: 2021/3/11 16:05
 */

@Repository
public interface TripleDAO extends JpaRepository<Triple,Integer>{

    List<Triple>findByKgID(int kgID);

    List<Triple>findById(int Id);

    void deleteByKgID(int kgId);


    void deleteById(int Id);

    @Query(nativeQuery = true,value = "select * from se3.triple where kgID=?1 and (s_id=?2 or o_id=?2)")
    List<Triple>TripleByKgIdAndS_idOr_O_id(int kgID,int NodeId);

    @Modifying
    @Query(nativeQuery = true,value = "delete from se3.triple where kgID=?1 and (s_id=?2 or o_id=?2)")
    void deleteTripleWhenDeleteNode(int kgId,int NodeId);

    @Query(nativeQuery = true,value = "select * from se3.triple where kgID=?1 and s_id=?2 and o_id=?3")
    List<Triple>TripleByKgIdAndS_idAndO_id(int kgId,int s_id,int o_id);

    @Query(nativeQuery = true,value = "select * from se3.triple where kgID=?1 and s_id=?2 and o_id=?3 and predicate=?4")
    List<Triple>TripleByKgIdAndS_idAndO_idAndPredicate(int kgId,int s_id,int o_id,String Predicate);

    @Modifying
    @Query(nativeQuery = true,value = "insert into se3.triple" +
            "(id, kgID, s_id, o_id, predicate) " +
            "values (?1,?2,?3,?4,?5)")
    void insert_when_cancel(int id,int kgID,int s_id,int o_id,String predicate);



}
